//
// File:	Variant.hpp
// Author:	Thomas TISSOT-DUPONT
// Login:	<thomas.tissotdupont@free.fr>
//
// Created:	17/04/2010 at 19:18:13
// Purpose:	
//
#ifndef VARIANT_HPP
#define VARIANT_HPP

#include <string>
#include <sstream>

//------------------------------------------------------------------
// Basic Variant Class
//------------------------------------------------------------------
class Variant
{
public:
					Variant();
					Variant(bool);
					Variant(int);
					Variant(unsigned int);
					Variant(float);
					Variant(const std::string &source);

public:
	inline std::string		ToString() const		{ return m_value; }
	inline bool				ToBool() const			{ return m_bValue; }
	inline int				ToInt() const			{ return m_iValue; }
	inline unsigned int		ToUInt() const			{ return m_uValue; }
	inline float			ToFloat() const			{ return m_flValue; }

public:
	inline operator std::string() const				{ return ToString(); }
	inline operator bool() const					{ return ToBool(); }
	inline operator int() const						{ return ToInt(); }
	inline operator unsigned int() const			{ return ToUInt(); }
	inline operator float() const					{ return ToFloat(); }

private:
	template <typename T>
	T ConvertFromString(const std::string &source) const
	{
		T result;
		std::istringstream(source) >> result;
		return result;
	}

	template <typename T>
	std::string ConvertToString(T source) const
	{
		std::string result;
		std::ostringstream oss;
		oss << source;
		std::istringstream(oss.str()) >> result;
		return result;
	}

private:
	std::string			m_value;
	bool				m_bValue;
	int					m_iValue;
	unsigned int		m_uValue;
	float				m_flValue;
};

#endif //!VARIANT_HPP
